<template>
  <div class="che-login">
    <div class="container">
      <div class="title">
                <span class="t0">
                    <img src="@/assets/logo.png" />
                </span>
        <span class="t1">Connect Wallet</span>
        <span class="t2">To start using Multiple Finance</span>
      </div>
      <div>
        <a-button class="btn-item" v-for="(item,index) in btns" :key="item.label" type="primary" block
                  @click="toLogin(item)">
          <span class="p1">{{item.label}}</span>
          <span class="p2">
                            <img :src="require('../assets/wallet-icon/'+item.name+'.svg')"/>
                    </span>
        </a-button>
      </div>
      <a-button class="close" icon="close" @click="closePage"></a-button>
    </div>
  </div>
</template>

<script>

  import {trace} from "../utils/tools"
  import {mapActions} from "vuex"

  export default {
    name:"loginWallet",
    components: {},
    props: {},
    data() {
      return {
        btns: [
          {
            id: 1,
            label: "MateMask",
            name: "matemask",
            icon: "",
          },
          // {
          //     id: 2,
          //     label: "Coinbase Wallet",
          //     icon: "",
          // },
          {
            id: 3,
            label: "Wallet Connect",
            name: "walletconnect",
            icon: "",
          },
          // {
          //     label: "Formatic",
          //     icon: "",
          // },
          // {
          //     id: 4,
          //     label: "Portis",
          //     icon: "",
          // },
        ]
      };
    },
    methods: {
      ...mapActions(['loginm']),
      async toLogin(item) {
        if(this.isLogin){
          return;
        }
        trace("login-", item);
        // "walletconnect" | "metamask" | "huobiwallet" | "mathwallet" | "tokenpocket"
        // logins(item.name, (res) => {
        //   trace("----change----", res);
        // })
        let data = await this.loginm( item.name, (res) => {
          trace("----change----", res);
        })
        // let data = await this.$store.dispatch('user/logins', item.name, (res) => {
        //   trace("----change----", res);
        // })

        // let balance = await getBalanceToken("0xsfagsj");

        trace("data", data, "  balance=")
        if(data.account.length>12){     //登入成功
          this.closePage();
        }

      },
      closePage(){
        this.$bus.emit("showLogin", false);
      }
    },
    watch: {
      "$store.getters.isMobile"(newVal, oldVal) {
        this.isMobile = newVal;
      },
    },
    computed: {

    },

    mounted() {
    },
  };
</script>
<style lang="less" scoped>
  .che-login {
    background-color: rgba(0, 0, 0, 0.5);

    .container {
      position: relative;
      width: 600px;
      min-height: 60vh;
      margin: 8rem auto;
      background-color: white;
      padding: 3rem 2rem;
      border-radius: 1rem;
      box-shadow: 0px 0px 5px 5px rgb(205 224 219 / 10%);
      .close{
        position: absolute;
        right: 1.5rem;
        top: 1rem;
        border: 0;
        font-size: 1.2rem;
      }
      .title{
        position: relative;
        text-align: center;
        color: #13C496;
        display: flex;
        flex-direction: column;
        text-align: center;
        color: #13C496;
        margin: 2rem 0;

        .t0{
          width: 72px;
          height: 72px;
          background: #13C496;
          box-shadow: 0px 8px 24px 0px rgb(65 163 114 / 30%);
          margin: auto;
          border-radius: 72px;
          overflow: hidden;

          img{
            width: 100%;
            /*width: 50%;*/
            /*margin: 25%;*/
            /*filter: drop-shadow(2px 4px 6px white);*/
          }
        }
        .t1{
          font-size: 22px;
          /*font-family: PingFangSC-Semibold, PingFang SC;*/
          font-weight: 600;
          line-height: 30px;
          margin: 12px 0;
        }

        .t2{
          font-size: 16px;
          /*font-family: PingFangSC-Semibold, PingFang SC;*/
          font-weight: 600;
          line-height: 22px;
        }
      }
      .btn-item:hover{
        background: rgba(19, 196, 150, 0.2);
        border: 1px solid #13C496;
      }

      .btn-item {
        margin: 1rem;
        width: 532px;
        height: 83px;
        background: #FDFDFD;
        border-radius: 19px;
        border: 1px solid rgba(68, 68, 68, 0.2);
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 36px;

        .p1 {
          font-size: 18px;
          /*font-family: PingFangSC-Semibold, PingFang SC;*/
          font-weight: 600;
          color: #444444;
          line-height: 25px;
        }

        .p2 {
          width: 60px;

          img {
            width: 100%;
          }
        }

      }
    }
  }
</style>
